import socket

# 创建 socket 对象
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 连接到服务器
server_address = ('172.16.219.51', 9999)
client_socket.connect(server_address)

while True:
    # 发送消息给服务器
    message = input('请输入要发送给服务器的消息: ')
    client_socket.send(message.encode('utf-8'))

    # 接收服务器消息
    data = client_socket.recv(1024).decode('utf-8')
    if not data:
        break
    print('服务器说: {}'.format(data))
    # if (input("是否继续Y/N？")=="N"):
    #     break

# 关闭连接
client_socket.close()